"use strict";

/**
 * @auther wtfssd
 * Created by wtfssd on 2017/11/2
 */
import * as React from 'react'
import {SCREEN_WIDTH} from "../constant";
import {commonStyles} from "../assets/styles/common";

const {View, ScrollView, Image, ActionSheetIOS} = require('react-native');
const ImagePicker = require('react-native-image-picker');
import ImagePicker1 from 'react-native-image-crop-picker';
import {MyImagePickerOption} from "../interface/index";

const {Actions} = require("react-native-router-flux");

class MyImagePicker extends React.Component<any, any> {

    constructor(props: any, context: any,) {
        super(props, context);
        // console.log(props);
    }

    static showImagePicker(options: MyImagePickerOption, cb: (response) => void) {
        const _options = {
            title: null,
            cancelButtonTitle: '取消',
            takePhotoButtonTitle: '拍摄照片',
            chooseFromLibraryButtonTitle: '选择现有照片',
            customButtons: null,
            cameraType: 'back',
            mediaType: 'photo',
            maxWidth: SCREEN_WIDTH,
            allowsEditing: false,
        };
        // console.log(options);
        // ActionSheetIOS.showActionSheetWithOptions({
        //     options:['拍摄照片','选择现有照片','取消'],
        //     cancelButtonIndex:2,
        // },(index)=>{
        //     console.log(index);
        //     if(index ===1 ){
        //
        //     }
        // });
        ImagePicker.showImagePicker(_options, (response) => {
            if (response.didCancel) {
                // console.log('cancel');
            }
            else if (response.error) {

            }
            else if (response.customButton) {

            }
            else {
                ImagePicker1.openCropper({mediaType: 'photo', ...options, path: response.uri}).then(image => {
                    cb(image)
                }).catch((e) => {

                });
            }
        });
    }

    static launchCamera(options,cb) {
        ImagePicker.launchCamera(options,cb);
    }

    static launchImageLibrary() {

    }


    render() {
        return (
            <View style={[commonStyles.container, commonStyles.centerVH, {backgroundColor: 'rgba(0,0,0,0.5)'}]}>

            </View>
        )
    }
}


export default MyImagePicker;
